<?php

namespace App\Jobs;

use App\Helpers\PerFormanceTrait;
use App\Models\Bill;
use App\Models\OnJobLog;
use App\Models\PerformanceTable;
use App\Models\Student;
use App\Models\SystemUser;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;

class HangJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PerFormanceTrait;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
         $order = OnJobLog::query()
            ->where('status','<',3)
            ->where('expire_at','<',now())
             ->get();
         foreach ($order as $v){
             if($v->is_fee==2){
                 Student::query()->where('id',$v->student_id)->update(['on_job'=>2]);
                 $v->status = 5;
                 $v->save();
             }else{
                 $v->is_hang = 2;
                 $v->save();
             }
         }

    }


}
